package com.android.fragmentdemo.adapters
import androidx.recyclerview.widget.GridLayoutManager
import androidx.recyclerview.widget.LinearLayoutManager
import com.android.fragmentdemo.R
import com.android.fragmentdemo.databeans.DataFactoryIp
import com.android.fragmentdemo.databinding.RvNestingRvItemLayoutBinding
import com.android.fragmentdemo.defineviews.Dy0101ItemDecoration
import com.android.fragmentdemo.defineviews.GridItemDecoration
import com.android.fragmentdemo.defineviews.List01DataItemDecoration
import com.hengfoxwolf.commonbase.base.adapter.BaseRvMultiTypeAdapter

class RvNestingRvAdapter :
    BaseRvMultiTypeAdapter<RvNestingRvItemLayoutBinding,RvNestingRvItemLayoutBinding, RvNestingRvItemLayoutBinding>
        (RvNestingRvItemLayoutBinding::inflate,RvNestingRvItemLayoutBinding::inflate,RvNestingRvItemLayoutBinding::inflate) {

    override fun bindData(holder: ViewHolder, position: Int) {
        when (position) {
            0 -> {
                val dyAdapter = DynamicItem01Adapter()
                dyAdapter.itemDataSet = DataFactoryIp.createCharStr(10)
                (holder.binding as RvNestingRvItemLayoutBinding).itemSuRv.apply {
                    layoutManager = LinearLayoutManager(
                        mContext,
                        LinearLayoutManager.HORIZONTAL,
                        false
                    )
                    adapter = dyAdapter
                    addItemDecoration(
                        Dy0101ItemDecoration(
                            mContext!!.resources.getDimension(
                                R.dimen.dp_10
                            )
                        ).apply {
                            setFirstItemSpace(true)
                        }
                    )
                }
            }
            1 -> {
                val dyAdapter = DynamicItem02Adapter()
                dyAdapter.itemDataSet = DataFactoryIp.createColorList()
                (holder.binding as RvNestingRvItemLayoutBinding).itemSuRv.apply {
                    layoutManager = GridLayoutManager(
                        mContext,
                        4
                    )
                    adapter = dyAdapter
                    addItemDecoration(GridItemDecoration(mContext!!, 4))
                }
            }
            else -> {
                val dyAdapter = DynamicItem03Adapter()
                dyAdapter.itemDataSet = DataFactoryIp.createStrDataSet()
                (holder.binding as RvNestingRvItemLayoutBinding).itemSuRv.apply {
                    layoutManager = LinearLayoutManager(
                        mContext,
                    )
                    adapter = dyAdapter
                    addItemDecoration(
                        List01DataItemDecoration(
                            mContext!!,
                            mContext!!.resources.getDimension(R.dimen.dp_10)
                        ).apply {
                            setDrawLastLine(false)
                        })
                }
            }
        }
    }
}